package com.sl.eurekaserver.controller;

import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.sl.eurekaserver.command.UserCommand;
import com.sl.eurekaserver.entity.User;
import com.sl.eurekaserver.service.HelloService;

 
@RestController
public class HelloController {
	
	@Autowired
	private RestTemplate restTemplate;
	
	@Autowired
	private HelloService helloService;

	@RequestMapping(value="/cunstomer", method=RequestMethod.GET)
	@ResponseBody
	public String index(){
		return helloService.helloService();
	}
	
	public void test() {
		try {
			// 同步执行 ：
			User user = new UserCommand(restTemplate, "xxx").execute();
			// 异步执行：
			Future<User> future = new UserCommand(restTemplate, "xxx").queue();
			// 获取异步里面的结果
			future.get();
			
			rx.Observable<User> ho = new UserCommand(restTemplate, "zzz").observe();
			rx.Observable<User> co = new UserCommand(restTemplate, "zzz").toObservable();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
